package com.psdi.manager;

import com.psdi.element.Player;
import com.psdi.element.Tag;

/**
 * 等级系统类
 * 用于管理游戏中的关卡和经验值系统
 */
public class LevelSystem {

    private static LevelSystem INSTANCE = null;

    private int EXP = 0;
    private int level = 0;
    private final static int maxlevel = 8;
    private int maxEXP = 2; //拾取多少经验值道具升级

    public int getEXP() {
        return EXP;
    }

    public void setEXP(int EXP) {
        this.EXP = EXP;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getMaxEXP() {
        return maxEXP;
    }

    public static synchronized LevelSystem getINSTANCE() {
        if (INSTANCE == null) {
            INSTANCE = new LevelSystem();
        }
        return INSTANCE;
    }

    public void EXP_Up(){
        EXP++;
        if(EXP >= maxEXP && level < maxlevel){
            levelUP();
            EXP = 0;
            maxEXP *=2;
        }

    }
    public void levelUP(){
        level++;
        //TODO 升级时需要进行的操作
        if(!ElementManager.getINSTANCE().getGameElements().get(Tag.PLAYER).isEmpty()) {
            Player player = (Player)ElementManager.getINSTANCE().getGameElements().get(Tag.PLAYER).get(0);
            //增加攻击力
            player.setAtk(player.getAtk() + 2);
            //增加移动速度
            player.setSpeed(player.getSpeed() * 1.15f);
            //增加血量
            player.setMaxhp(player.getMaxhp() + 1);
            player.setHp(player.getMaxhp());
            //增加攻速
            player.setDefaultAttackCooldown(player.getDefaultAttackCooldown()*0.9f);
        }
    }
}
